package com.zxj.schoolxianyu.service;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.zxj.schoolxianyu.dao.browsinghistoryDao;
import com.zxj.schoolxianyu.dao.goodsDao;
import com.zxj.schoolxianyu.entity.browsinghistory;
import com.zxj.schoolxianyu.entity.goods;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class getBrowseHisGoodsService {
    @Autowired(required = false)
    private browsinghistoryDao browsinghistoryDao;
    @Autowired(required = false)
    private goodsDao goodsDao;

    public String getHisGoods(String username) {
        EntityWrapper<browsinghistory> b = new EntityWrapper<>();
        EntityWrapper<goods> g = new EntityWrapper<>();
        b.eq("username", username);
        System.out.println(username);
        List<browsinghistory> bs = browsinghistoryDao.selectList(b);
        System.out.println(bs);
        List<Integer> gsid = new ArrayList<Integer>();
        for (int i = 0; i < bs.size(); i++) {
            gsid.add(bs.get(i).goodsid);
        }
        System.out.println(gsid);
        g.in("goodsid", gsid);
        List<goods> gs = goodsDao.selectList(g);
        if (gs.isEmpty()) return "No more data";
        else return JSON.toJSONString(gs);
    }
}
